home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / system-tools / tinymeter / source / tinymeter_main / handler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-22  |  22.0 KB  |  760 lines

  1. #include <intuition/classusr.h>
  2. #include <intuition/gadgetclass.h>
  3. #include <intuition/cghooks.h>
  4. #include <intuition/icclass.h>
  5. #include <intuition/classes.h>
  6. #include <utility/tagitem.h>
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <dos/dos.h>
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <dos/notify.h>
  13. #include <intuition/intuition.h>
  14. #include <libraries/SysInfo.h>
  15. #include <utility/tagitem.h>
  16. #include <clib/macros.h>
  17. #include <libraries/commodities.h>
  18. #include <libraries/ScreenNotify.h>
  19. #include <datatypes/datatypesclass.h>
  20. #include <datatypes/datatypes.h>
  21. #include <datatypes/pictureclass.h>
  22. #include "gaugeclass.h"
  23. #include "launchclass.h"
  24. #include "tinymeter.h"
  25.  
  26. extern struct Library *RetinaBase;
  27.  
  28. extern ULONG idle;
  29.  
  30. #define test_test       0
  31. #define test_getwin     1
  32.  
  33. #define do_clock        1
  34. #define do_mem          2
  35. #define do_vol          3
  36.  
  37. struct TestMessage
  38. {
  39.     struct  Message ts_Message;
  40.     ULONG   MethodID;
  41.     struct  tm_sys_set  *set;
  42.     struct  tm_gau_set  *list;
  43.     ULONG   posx,
  44.         posy,
  45.         sizx;
  46. };
  47.  
  48. init_time_request(struct timerequest *my_time_request_clock, ULONG my_time_mask_clock)
  49. {
  50.     ULONG interval;
  51.     my_time_request_clock -> tr_node.io_Command     = TR_GETSYSTIME;
  52.     DoIO(my_time_request_clock);
  53.     interval=my_time_request_clock -> tr_time.tv_secs;
  54.     my_time_request_clock -> tr_node.io_Command     = TR_ADDREQUEST;
  55.     my_time_request_clock -> tr_time.tv_secs        = interval+1;
  56.     my_time_request_clock -> tr_time.tv_micro       = NULL;
  57.     SetSignal(NULL,my_time_mask_clock);
  58.     SendIO(my_time_request_clock);
  59. }
  60.  
  61. ULONG snapSub(struct tm_sys_set *set, struct tm_data *data)
  62. {
  63.     struct lau_enty         *list;
  64.     int                     i;
  65.     struct IntuiMessage     *m;
  66.  
  67.     while((m=(struct IntuiMessage *)GetMsg( data->win->UserPort )))ReplyMsg( m );
  68.     data->win=(struct Window *) snapBackground(set,data);
  69.                 drawBackground(set,data);
  70.     for(i=NULL;i<data->num_of_gaug;i++)
  71.     {
  72.     if(data->gdg[i])
  73.     {
  74.         GetAttr(LAU_List,data->gdg[i],&list);
  75.         if(list) AddGList(data->win,data->gdg[i],0,1,NULL);
  76.         else     AddGList(data->win,data->gdg[i],-1,1,NULL);
  77.         SetAttrs(data->gdg[i],GA_Width, data->gauge_x_size, NULL);
  78.     }
  79.     }
  80.     RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  81.     return(1L << data->win->UserPort->mp_SigBit);
  82. }
  83.  
  84. setBase(struct tm_data *data)
  85. {
  86.     struct tm_gau_set   *many;
  87.     int                 i;
  88.     ULONG               cur;
  89.     for(i=NULL,many=data->list;i<data->num_of_gaug;i++,many=many->next)
  90.     {
  91.     if(data->gdg[i])
  92.     {
  93.         GetAttr(GAU_Current,data->gdg[i],&cur);
  94.         SetAttrs(data->gdg[i],GAU_Current,cur,GAU_Base,cur,TAG_DONE);
  95.     }
  96.     }
  97.     RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  98. }
  99.  
  100. handle_launcher(struct tm_data *data, UWORD ID, struct Gadget *obj)
  101. {
  102.     struct  Window          *lwin;
  103.     struct  RastPort        *rp,
  104.                 tmpras;
  105.     BOOL                    foo=TRUE,
  106.                 start=FALSE;
  107.     struct  lau_entry       *entry,
  108.                 *foobar;
  109.     LONG                    dummy,
  110.                 height,
  111.                 width;
  112.     LONG                    x,
  113.                 y,
  114.                 selected,
  115.                 sigs,
  116.                 lastsel;
  117.     ULONG                   pen_bg,
  118.                 pen_bright,
  119.                 pen_dark,
  120.                 pen_cur,
  121.                 pen_entry,
  122.                 window_mask,
  123.                 lwindow_mask,
  124.                 down;
  125.     UWORD                   entryheight,
  126.                 iw=NULL,
  127.                 y_pos;
  128.     struct IntuiMessage     *m;
  129.     struct BitMapHeader     *bmhd;
  130.     struct BitMap           *bm;
  131.  
  132.     GetAttr(LAU_ColEntry     ,obj,&pen_entry);
  133.     GetAttr(LAU_ColBrightEdg ,obj,&pen_bright);
  134.     GetAttr(LAU_ColDarkEdg   ,obj,&pen_dark);
  135.     GetAttr(LAU_ColBackground,obj,&pen_bg);
  136.     GetAttr(LAU_ColCursor    ,obj,&pen_cur);
  137.     GetAttr(LAU_List         ,obj,&entry);
  138.     GetAttr(LAU_Down         ,obj,&down);
  139.     if(foobar=entry)
  140.     {
  141.     InitRastPort(&tmpras);
  142.     SetFont(&tmpras,data->Font[ID]);
  143.     dummy=NULL;
  144.     entryheight=data->Font[ID]->tf_YSize;
  145.     width=data->gdg[ID]->Width+2;
  146.     do
  147.     {
  148.         if(foobar->img)
  149.         {
  150.         GetDTAttrs(foobar->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  151.         if(bmhd)
  152.         {
  153.             entryheight=MAX(entryheight,bmhd->bmh_Height+2);
  154.             iw=MAX(iw,bmhd->bmh_Width+6);
  155.         }
  156.         }
  157.         foobar->width=TextLength(&tmpras,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  158.         width=MAX(width,foobar->width+12+iw);
  159.         dummy++;
  160.     }
  161.     while(foobar=foobar->next);
  162.  
  163.     y_pos=((entryheight-((data->Font[ID]->tf_Baseline+data->Font[ID]->tf_YSize)>>1))>>1);
  164.     if(data->Font[ID]->tf_Baseline<data->Font[ID]->tf_YSize)
  165.     {
  166.         y_pos+=data->Font[ID]->tf_Baseline-1;
  167.         if(y_pos<data->Font[ID]->tf_Baseline)y_pos=data->Font[ID]->tf_Baseline;
  168.     }
  169.     else
  170.     {
  171.         y_pos+=data->Font[ID]->tf_YSize-1;
  172.         if(y_pos<data->Font[ID]->tf_YSize)   y_pos=data->Font[ID]->tf_YSize;
  173.     }
  174.  
  175.     height=(entryheight*dummy)+2;
  176.     y=data->gdg[ID]->TopEdge+data->win->TopEdge-( down==lau_up ? height : ( down== lau_down ? -data->gdg[ID]->Height : height>>1 ));
  177.     if((lwin=(struct Window *)OpenWindowTags(NULL,
  178.         WA_Left,            data->gdg[ID]->LeftEdge+data->win->LeftEdge-1,
  179.         WA_Top,             y,
  180.         WA_Width,           width,
  181.         WA_Height,          height,
  182.         WA_Flags,           WFLG_BORDERLESS|WFLG_REPORTMOUSE|WFLG_RMBTRAP|WFLG_ACTIVATE,
  183.         WA_PubScreen,       data->scr,
  184.         WA_IDCMP,           IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE,
  185.         TAG_END)))
  186.     {
  187.         selected     =-1;
  188.         lastsel      =-1;
  189.         window_mask  = 1L << data->win->UserPort->mp_SigBit;
  190.         lwindow_mask = 1L << lwin->UserPort->mp_SigBit;
  191.  
  192.         SetFont(rp=lwin->RPort,data->Font[ID]);
  193.         SetAPen(rp,pen_bg); RectFill(rp,0,0,width-1,height-1);
  194.         draw_border_new(rp,0,0,width,height,pen_bright,pen_dark);
  195.         SetAPen(rp,pen_entry);
  196.         SetDrMd(rp,JAM1);
  197.         foobar=entry;
  198.         dummy=0;
  199.         do
  200.         {
  201.         if(foobar->img)
  202.         {
  203.             GetDTAttrs(foobar->img,PDTA_BitMapHeader,&bmhd,PDTA_DestBitMap,&bm,TAG_DONE);
  204.             if (!bm) GetDTAttrs(foobar->img,PDTA_BitMap,&bm,TAG_DONE);
  205.             BltBitMapRastPort(bm,0,0,rp,2+((iw-bmhd->bmh_Width)>>1),(dummy*entryheight)+1+((entryheight-bmhd->bmh_Height)>>1),bmhd->bmh_Width,bmhd->bmh_Height,0xc0);
  206.         }
  207.         Move(rp,iw+7,((dummy++)*entryheight)+y_pos+1);
  208.         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  209.         }
  210.         while(foobar=foobar->next);
  211.         while(foo)
  212.         {
  213.         sigs=Wait( window_mask | lwindow_mask );
  214.         if(sigs & window_mask);
  215.         {
  216.             while(m=(struct IntuiMessage *)GetMsg(data->win->UserPort))
  217.             {
  218.             switch (m->Class)
  219.             {
  220.                 case    IDCMP_GADGETDOWN:
  221.                     foo=FALSE;
  222.                     break;
  223.             }
  224.             ReplyMsg(m);
  225.             }
  226.         }
  227.         if(sigs & lwindow_mask)
  228.         {
  229.             while(m=(struct IntuiMessage *)GetMsg(lwin->UserPort))
  230.             {
  231.             switch (m->Class)
  232.             {
  233.                 case    IDCMP_MOUSEBUTTONS:
  234.                     if((m->Code&15)==8)
  235.                     {
  236.                     selected=(m->MouseY-1)/entryheight;
  237.                     foo=FALSE;
  238.                     start=TRUE;
  239.                     }
  240.                     break;
  241.                 case    IDCMP_MOUSEMOVE:
  242.                     x=m->MouseX;
  243.                     y=m->MouseY;
  244.                     if((x>0)&&(y>0)&&(x<(width-1))&&(y<(height-1)))
  245.                     {
  246.                     selected=(y-1)/entryheight;
  247.                     if(selected!=lastsel)
  248.                     {
  249.                         if(lastsel!=-1)
  250.                         {
  251.                         SetAPen(rp,pen_bg);
  252.                         RectFill(rp,iw+3,1+(lastsel*entryheight),width-4,((lastsel+1)*entryheight));
  253.                         SetAPen(rp,pen_entry);
  254.                         for(foobar=entry,dummy=0;dummy<lastsel;dummy++)foobar=foobar->next;
  255.                         Move(rp,iw+7,(lastsel*entryheight)+y_pos+1);
  256.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  257.                         }
  258.                         SetAPen(rp,pen_cur);
  259.                         RectFill(rp,iw+3,1+(selected*entryheight),width-4,((selected+1)*entryheight));
  260.                         SetAPen(rp,pen_entry);
  261.                         for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  262.                         Move(rp,iw+7,(selected*entryheight)+y_pos+1);
  263.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  264.                     }
  265.                     lastsel=selected;
  266.                     }
  267.                     else
  268.                     {
  269.                     if(lastsel!=-1)
  270.                     {
  271.                         SetAPen(rp,pen_bg);
  272.                         RectFill(rp,iw+1,1+(lastsel*entryheight),width-2,((lastsel+1)*entryheight));
  273.                         SetAPen(rp,pen_entry);
  274.                         for(foobar=entry,dummy=0;dummy<lastsel;dummy++)foobar=foobar->next;
  275.                         Move(rp,iw+7,(lastsel*entryheight)+y_pos+1);
  276.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  277.                     }
  278.                     selected=-1;
  279.                     lastsel=-1;
  280.                     }
  281.                     break;
  282.             }
  283.             ReplyMsg(m);
  284.             }
  285.         }
  286.         }
  287.         while(m=(struct IntuiMessage *)GetMsg(data->win->UserPort))ReplyMsg(m);
  288.         while(m=(struct IntuiMessage *)GetMsg(lwin->UserPort))     ReplyMsg(m);
  289.         CloseWindow(lwin);
  290.         if(start&&(selected>-1))
  291.         {
  292.         for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  293.         RunFile(foobar,data);
  294.         }
  295.     }
  296.     else DisplayBeep(0);
  297.     }
  298. }
  299.  
  300. subRefresh(struct tm_data *data, int i)
  301. {
  302.     BeginRefresh(data->win);
  303.     EndRefresh(data->win,TRUE);
  304.     RefreshGList(data->gdg[i], data->win,NULL,1);
  305. }
  306.  
  307. struct tm_sys_set *handler(struct tm_sys_set *set, struct tm_data *data, struct MsgPort *broker_mp, CxObj *broker, ULONG cxsigflag, Class *gclass, Class *lclass)
  308. {
  309.     BOOL                        running = TRUE;
  310.  
  311.     ULONG                       mem_val=0,
  312.                 vol_val=0,
  313.                 sigs,
  314.                 window_mask,
  315.                 my_time_mask_clock,
  316.                 my_test_port_mask,
  317.                 my_noti_port_mask=0L,
  318.                 my_app_port_mask =0L,
  319.                 my_handler;
  320.  
  321.     struct MsgPort             *my_time_port_clock,
  322.                    *my_test_port,
  323.                    *my_noti_port;
  324.  
  325.     struct timerequest         *my_time_request_clock;
  326.  
  327.     struct NotifyRequest       *notifyrequest;
  328.     LONG                        not_sig;
  329.     BOOL                        closed=FALSE;
  330.  
  331.     struct IntuiMessage        *m;
  332.     int                         i;
  333.     ULONG                       cur;
  334.     ULONG                       bas;
  335.     struct TestMessage         *test_msg;
  336.     struct tm_gau_set          *many,*next;
  337.     BOOL                        first_run=TRUE;
  338.     UWORD                       do_what;
  339.  
  340.     if(data->scrnot)
  341.     {
  342.     my_noti_port        = (struct MsgPort *)CreateMsgPort();
  343.     my_handler          = ((!data->on_public)|(!strcmp(&set->pub_name[0],"Workbench"))) ? (ULONG)AddWorkbenchClient(my_noti_port,0) : (ULONG)AddCloseScreenClient(data->scr,my_noti_port,0);
  344.     my_noti_port_mask   = 1L << my_noti_port->mp_SigBit;
  345.     }
  346.  
  347.     if(data->appwin)
  348.     {
  349.     my_app_port_mask    = 1L << data->appport->mp_SigBit;
  350.     }
  351.  
  352.     window_mask  = 1L << data->win->UserPort->mp_SigBit;
  353.  
  354.     if(my_test_port=(struct MsgPort *)CreatePort("TinyMeter",0))
  355.     {
  356.     my_test_port_mask = 1L << (my_test_port->mp_SigBit);
  357.     if(my_time_port_clock=(struct MsgPort *)CreateMsgPort())
  358.     {
  359.         my_time_mask_clock    = 1L << (my_time_port_clock->mp_SigBit);
  360.         if(my_time_request_clock = (struct timerequest *)CreateIORequest(my_time_port_clock,sizeof(struct timerequest)))
  361.         {
  362.         if(!OpenDevice("timer.device",UNIT_WAITUNTIL,my_time_request_clock,NULL))
  363.         {
  364.             if(notifyrequest = (struct NotifyRequest *)AllocVec(sizeof(struct NotifyRequest),MEMF_CLEAR|MEMF_PUBLIC))
  365.             {
  366.             if ((not_sig = AllocSignal(-1L)) != -1)
  367.             {
  368.                 notifyrequest->nr_Name                          = "ENV:Sys/WBPattern.prefs";
  369.                 notifyrequest->nr_Flags                         = NRF_SEND_SIGNAL;
  370.                 notifyrequest->nr_stuff.nr_Signal.nr_Task       = (struct Task *) FindTask(NULL);
  371.                 notifyrequest->nr_stuff.nr_Signal.nr_SignalNum  = not_sig;
  372.                 if((StartNotify(notifyrequest))==DOSTRUE)
  373.                 {
  374.                 init_time_request(my_time_request_clock,my_time_mask_clock);
  375.                 while(running)
  376.                 {
  377.                     sigs = Wait( my_noti_port_mask | my_test_port_mask | window_mask | my_time_mask_clock | (1L << not_sig) | cxsigflag | my_app_port_mask );
  378.                     if(!closed)
  379.                     {
  380.                     if (sigs & my_time_mask_clock)
  381.                     {
  382.                         init_time_request(my_time_request_clock,my_time_mask_clock);
  383.                         do_what=do_clock;
  384.                         mem_val++;
  385.                         if(mem_val>=set->mem_refresh)
  386.                         {
  387.                         mem_val=0;
  388.                         do_what=do_mem;
  389.                         }
  390.                         vol_val++;
  391.                         if(vol_val>=set->vol_refresh)
  392.                         {
  393.                         vol_val=0;
  394.                         do_what=do_vol;
  395.                         }
  396.                         for(i=0,many=data->list;i<data->num_of_gaug;i++,many=many->next)
  397.                         {
  398.                         if(data->gdg[i]!=0)
  399.                         switch (do_what)
  400.                         {
  401.                             case    do_vol:
  402.                                 if(many->type==typ_volume)
  403.                                 {
  404.                                 getVolsize(data,&many->expansion[0]);
  405.                                 SetAttrs(data->gdg[i],GAU_VolType,data->voltype,GAU_Max,data->volmax,GAU_Current,data->volcur,TAG_DONE);
  406.                                 subRefresh(data,i);
  407.                                 }
  408.                             case    do_mem:
  409.                                 switch (many->type)
  410.                                 {
  411.                                 case    typ_all:
  412.                                     cur=AvailMem(0L);
  413.                                     break;
  414.                                 case    typ_chip:
  415.                                     cur=AvailMem(MEMF_CHIP);
  416.                                     break;
  417.                                 case    typ_fast:
  418.                                     cur=AvailMem(MEMF_FAST);
  419.                                     break;
  420.                                 case    typ_idle:
  421.                                     GetAttr(GAU_Current,data->gdg[i],&bas);
  422.                                     switch (data->executive)
  423.                                     {
  424.                                         case    idle_none:
  425.                                             cur=0L;
  426.                                             break;
  427.                                         case    idle_executive:
  428.                                             GetCpuUsage(data->si,&data->cpu);
  429.                                             cur=(data->cpu.used_cputime_lastsec_hz-data->cpu.used_cputime_lastsec)<<8;
  430.                                             break;
  431.                                         case    idle_own:
  432.                                             cur=idle;
  433.                                             break;
  434.                                     }
  435.                                     if(bas<cur)SetAttrs(data->gdg[i],GAU_Base,cur,TAG_DONE);
  436.                                     break;
  437.                                 case    typ_largest_total:
  438.                                     cur=AvailMem(MEMF_LARGEST);
  439.                                     break;
  440.                                 case    typ_largest_chip:
  441.                                     cur=AvailMem(MEMF_LARGEST|MEMF_CHIP);
  442.                                     break;
  443.                                 case    typ_largest_fast:
  444.                                     cur=AvailMem(MEMF_LARGEST|MEMF_FAST);
  445.                                     break;
  446.                                 case    typ_largest_retina:
  447.                                     if(RetinaBase)
  448.                                         cur=Retina_AvailMem(MEMF_LARGEST);
  449.                                     else
  450.                                         cur=GAU_err_notavail;
  451.                                     break;
  452.                                 case    typ_retina:
  453.                                     if(RetinaBase)
  454.                                         cur=Retina_AvailMem(0L);
  455.                                     else
  456.                                         cur=GAU_err_notavail;
  457.                                     break;
  458.                                 case    typ_simplelauncher:
  459.                                 default:
  460.                                     goto none_4;
  461.                                     break;
  462.                                 }
  463.                                 if(do_what!=do_vol) goto none_5;
  464.                                 none_4:
  465.                             case    do_clock:
  466.                                 if(many->type==typ_clock_)
  467.                                 {
  468.                                 none_5:
  469.                                 SetAttrs(data->gdg[i],GAU_Current,cur,TAG_DONE);
  470.                                 subRefresh(data,i);
  471.                                 }
  472.                                 break;
  473.                         }
  474.                         }
  475.                         if(first_run){setBase(data);first_run=FALSE;}
  476.                         if(set->win_backfront==win_front) if(data->win->WLayer!=data->scr->LayerInfo.top_layer) WindowToFront(data->win);
  477.                     }
  478.                     if (sigs & my_app_port_mask)
  479.                     {
  480.                         struct AppMessage *appmsg;
  481.                         while(appmsg=(struct AppMessage *)GetMsg( data->appport))
  482.                         {
  483.                         DisplayBeep(0);
  484.                         ReplyMsg(appmsg);
  485.                         }
  486.                     }
  487.                     if (sigs & window_mask)
  488.                     {
  489.                         while(m=(struct IntuiMessage *)GetMsg( data->win->UserPort ))
  490.                         {
  491.                         switch ( m->Class )
  492.                         {
  493.                             case    IDCMP_GADGETDOWN:
  494.                                 {
  495.                                 struct Gadget *g=((struct Gadget *)(m->IAddress));
  496.                                 SetTaskPri(FindTask(0L),64);
  497.                                 ReplyMsg(m);
  498.                                 if(g->GadgetID<0xFFF0)
  499.                                 {
  500.                                     struct lau_entry *entry;
  501.                                     GetAttr(LAU_List,(Object *)g,&entry);
  502.                                     if(entry->next)  handle_launcher(data,(UWORD)g->GadgetID,(struct Gadget *)g);
  503.                                     else             RunFile(entry,data);
  504.                                 }
  505.                                 SetTaskPri(FindTask(0L),set->pri);
  506.                                 }
  507.                                 break;
  508.                             case    IDCMP_CHANGEWINDOW:
  509.                                 ReplyMsg( m );
  510.                                 if(set->bg_type==bg_snap) window_mask=snapSub(set,data);
  511.                                 break;
  512.                             case    IDCMP_CLOSEWINDOW:
  513.                                 running=FALSE;
  514.                                 ReplyMsg( m );
  515.                                 break;
  516.                             case    IDCMP_NEWSIZE:
  517.                                 ReplyMsg( m );
  518.                                 new_window_size(set,data);
  519.                                 set->x_siz=data->win->Width;
  520.                                 data->gauge_x_size=(set->x_siz-(set->win_border_x<<1)-((set->colums-1)*set->win_space_x))/set->colums;
  521.                                 if(set->bg_type==bg_file) fileBackground(set,data);
  522.                                 drawBackground(set,data);
  523.                                 for(i=0,many=data->list;i<data->num_of_gaug;i++,many=many->next) if(data->gdg[i]) SetAttrs(data->gdg[i],GA_Left,set->win_border_x+((i)%set->colums)*data->gauge_x_size+((i)%set->colums)*set->win_space_x,GA_Width,data->gauge_x_size,TAG_DONE);
  524.                                 if(set->bg_type!=bg_snap)RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  525.                                 if(set->bg_type==bg_snap)window_mask=snapSub(set,data);
  526.                                 break;
  527.                             case    IDCMP_VANILLAKEY:
  528.                                 {
  529.                                 int Code=m->Code;
  530.                                 ReplyMsg( m );
  531.                                 switch(Code)
  532.                                 {
  533.                                     case    'S':
  534.                                     case    's':
  535.                                         {
  536.                                         BPTR my_file,my_file1;
  537.                                         set->x_pos=data->win->LeftEdge;
  538.                                         set->y_pos=data->win->TopEdge;
  539.                                         set->x_siz=data->win->Width;
  540.                                         my_file= (BPTR)Open("ENV:TinyMeter",   MODE_NEWFILE);
  541.                                         my_file1=(BPTR)Open("ENVARC:TinyMeter",MODE_NEWFILE);
  542.                                         if(my_file) Write(my_file, set,(ULONG) sizeof(struct tm_sys_set));
  543.                                         if(my_file1)Write(my_file1,set,(ULONG) sizeof(struct tm_sys_set));
  544.                                         many=data->list;
  545.                                         for(i=0;i<data->num_of_gaug;i++)
  546.                                         {
  547.                                             if(my_file) Write(my_file, many,(ULONG) sizeof(struct tm_gau_set));
  548.                                             if(my_file1)Write(my_file1,many,(ULONG) sizeof(struct tm_gau_set));
  549.                                             many=many->next;
  550.                                         }
  551.                                         if(my_file) Close(my_file1);
  552.                                         if(my_file1)Close(my_file);
  553.                                         }
  554.                                         break;
  555.                                     case    'F':
  556.                                     case    'f':
  557.                                         {
  558.                                         ULONG   my_mem;
  559.                                         Forbid();
  560.                                         my_mem=AllocVec(2000000000L,MEMF_PUBLIC);
  561.                                         if(my_mem)FreeVec(my_mem);
  562.                                         Permit();
  563.                                         }
  564.                                         break;
  565.                                     case    'Q':
  566.                                     case    'q':
  567.                                         running=FALSE;
  568.                                         break;
  569.                                     case    'b':
  570.                                     case    'B':
  571.                                         if(set->bg_type==bg_snap)window_mask=snapSub(set,data);
  572.                                         break;
  573.                                 }
  574.                                 }
  575.                                 break;
  576.                             case    IDCMP_MOUSEBUTTONS:
  577.                                 if((m->Code&129)==1) setBase(data);
  578.                             default :
  579.                                 ReplyMsg( m );
  580.                                 break;
  581.                         }
  582.                         }
  583.                     }
  584.                     if (sigs & (1L << not_sig))
  585.                     {
  586.                         Delay(100L);
  587.                         if(set->bg_type==bg_snap) window_mask=snapSub(set,data);
  588.                     }
  589.                     }
  590.                     else if (sigs & my_time_mask_clock) init_time_request(my_time_request_clock,my_time_mask_clock);
  591.                     if (sigs & cxsigflag)
  592.                     {
  593.                     CxMsg *msg;
  594.                     ULONG msgid, msgtype;
  595.  
  596.                     while(msg = (CxMsg *)GetMsg(broker_mp))
  597.                     {
  598.                         msgid = CxMsgID(msg);
  599.                         msgtype = CxMsgType(msg);
  600.                         if(msgtype==CXM_COMMAND)
  601.                         {
  602.                         ReplyMsg((struct Message *)msg);
  603.                         switch(msgid)
  604.                         {
  605.                             case    CXCMD_DISABLE:
  606.                                 {
  607.                                 BOOL pause=TRUE;
  608.                                 ActivateCxObj(broker, 0L);
  609.                                 while(pause)
  610.                                 {
  611.                                     Wait(cxsigflag);
  612.                                     while(msg = (CxMsg *)GetMsg(broker_mp))
  613.                                     {
  614.                                     msgid = CxMsgID(msg);
  615.                                     msgtype = CxMsgType(msg);
  616.                                     ReplyMsg((struct Message *)msg);
  617.                                     if(msgtype==CXM_COMMAND) if(msgid==CXCMD_ENABLE) pause=FALSE;
  618.                                     }
  619.                                 }
  620.                                 ActivateCxObj(broker, 1L);
  621.                                 }
  622.                                 break;
  623.                             case    CXCMD_KILL:
  624.                                 running=FALSE;
  625.                             case    CXCMD_ENABLE:
  626.                                 ActivateCxObj(broker, 1L);
  627.                             default:
  628.                                 break;
  629.                         }
  630.                         }
  631.                         else ReplyMsg((struct Message *)msg);
  632.                     }
  633.                     }
  634.                     if ((sigs & my_test_port_mask)&&(!closed))
  635.                     {
  636.                     while(test_msg=(struct TestMessage *)GetMsg(my_test_port))
  637.                     {
  638.                         switch (test_msg->MethodID)
  639.                         {
  640.                         case    test_test:
  641.                             closeWindow(set,data);
  642.                             removeGadgets(set,data);
  643.                             first_run=TRUE;
  644.                             if(test_msg->set && test_msg->list)
  645.                             {
  646.                                 FreeVec(set);
  647.                                 many=data->list;
  648.                                 do
  649.                                 {
  650.                                 next=many->next;
  651.                                 FreeVec(many);
  652.                                 }
  653.                                 while(many=next);
  654.                                 set                 = test_msg->set;
  655.                                 data->list          = test_msg->list;
  656.                                 data->num_of_gaug   = getNum(data->list);
  657.                             }
  658.                             if(openWindow(set,data))
  659.                             {
  660.                                 drawBackground(set,data);
  661.                                 allocGadgets(set,data,gclass,lclass);
  662.                                 window_mask  = 1L << data->win->UserPort->mp_SigBit;
  663.                             }
  664.                             else running=FALSE;
  665.                             setBase(data);
  666.                             break;
  667.                         case    test_getwin:
  668.                             test_msg->posx=data->win->LeftEdge;
  669.                             test_msg->posy=data->win->TopEdge;
  670.                             test_msg->sizx=data->win->Width;
  671.                             break;
  672.                         }
  673.                         ReplyMsg(test_msg);
  674.                     }
  675.                     }
  676.                     if(data->scrnot)
  677.                     {
  678.                     if (sigs & my_noti_port_mask)
  679.                     {
  680.                         struct ScreenNotifyMessage  *snm;
  681.                         while(snm = (struct ScreenNotifyMessage *) GetMsg(my_noti_port))
  682.                         {
  683.                         switch(snm->snm_Type)
  684.                         {
  685.                             case    SCREENNOTIFY_TYPE_CLOSESCREEN:
  686.                                 running=FALSE;
  687.                                 break;
  688.                             case    SCREENNOTIFY_TYPE_WORKBENCH:
  689.                                 if((ULONG)snm->snm_Value)
  690.                                 {
  691.                                 if(closed)
  692.                                 {
  693.                                     Delay(50L);
  694.                                     if(openWindow(set,data))
  695.                                     {
  696.                                     drawBackground(set,data);
  697.                                     allocGadgets(set,data,gclass,lclass);
  698.                                     window_mask  = 1L << data->win->UserPort->mp_SigBit;
  699.                                     closed=FALSE;
  700.                                     }
  701.                                     else running=FALSE;
  702.                                     setBase(data);
  703.                                 }
  704.                                 }
  705.                                 else
  706.                                 {
  707.                                 if(!closed)
  708.                                 {
  709.                                     closeWindow(set,data);
  710.                                     removeGadgets(set,data);
  711.                                     closed=TRUE;
  712.                                 }
  713.                                 first_run=TRUE;
  714.                                 }
  715.                                 break;
  716.                         }
  717.                         ReplyMsg((struct Message *) snm);
  718.                         }
  719.                     }
  720.                     Delay(10L);
  721.                     }
  722.                 }
  723.                 EndNotify(notifyrequest);
  724.                 }
  725.                 else show(err_nosta);
  726.                 FreeSignal(not_sig);
  727.             }
  728.             else show(err_nosta);
  729.             FreeVec(notifyrequest);
  730.             }
  731.             else show(err_nomem);
  732.             if(!CheckIO(my_time_request_clock))
  733.             AbortIO(my_time_request_clock);
  734.             WaitIO(my_time_request_clock);
  735.             CloseDevice(my_time_request_clock);
  736.         }
  737.         else show(err_nodev);
  738.         DeleteIORequest(my_time_request_clock);
  739.         }
  740.         else show(err_nopor);
  741.         DeleteMsgPort(my_time_port_clock);
  742.     }
  743.     else show(err_nopor);
  744.     DeletePort(my_test_port);
  745.     }
  746.     else show(err_nopor);
  747.  
  748.     if(data->scrnot)
  749.     {
  750.     if((!data->on_public)|(!strcmp(&set->pub_name[0],"Workbench")))
  751.         while(!RemWorkbenchClient(my_handler)) Delay(10);
  752.     else
  753.         while(!RemCloseScreenClient(my_handler)) Delay(10);
  754.     DeleteMsgPort(my_noti_port);
  755.     }
  756.  
  757.     return(set);
  758. }
  759.  
  760.